package com.longteng.diamond.filter;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.Filter;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator
 * DATE : 2018/8/5
 * TIME : 13:41
 * PROJECT : java-lesson
 * PACKAGE : com.longteng.lesson
 *
 * @author <a href="mailto:taki@qq.com">Administrator</a>
 */
@Configuration
public class FilterConfigurer {
    @Bean
    public Filter urlFilter(){
        return new UrlFilter();
    }
    @Bean
    public FilterRegistrationBean filterRegistrationBean(){
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
        List<String> urlPatterns = new ArrayList<String>();
        //指定需要过滤的url
        urlPatterns.add("/*");
        filterRegistrationBean.setFilter(urlFilter());
        filterRegistrationBean.setUrlPatterns(urlPatterns);
        filterRegistrationBean.setOrder(0);
        return filterRegistrationBean;
    }
}
